package com.alibaba.citrus.ots.sales.plan.facade.service.setting.contract;

import com.alibaba.citrus.ots.common.annotation.FacadeInvoker;
import com.alibaba.citrus.ots.sales.plan.api.setting.contract.ContractQueryService;
import com.alibaba.citrus.ots.sales.plan.dto.api.request.*;
import com.alibaba.citrus.ots.sales.plan.repository.ContractRepository;
import com.alibaba.citrus.ots.sales.plan.sdo.ContractSDO;
import com.alibaba.cz.base.tool.page.PageResult;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangyibing
 */
@Service
public class ContractQueryServiceImpl implements ContractQueryService {
    @Resource
    private ContractRepository contractRepository;


    @FacadeInvoker
    @Override
    public Result<PageResult<List<ContractSDO>>> pageQueryContractList(PageQueryContractRequest contractRequest) {
        PageResult<List<ContractSDO>> doPageQuery = contractRepository.pageQuery(contractRequest,true);
        return Result.success(doPageQuery);
    }


    @FacadeInvoker
    @Override
    public Result<ContractSDO> queryContractById(QueryContractRequest queryContractRequest) {
        ContractSDO contractSdo = contractRepository.queryContractById(queryContractRequest);
        return Result.success(contractSdo);
    }

    @FacadeInvoker
    @Override
    public Result<List<MonthContractAndRollingCountResponse>> queryQuantityListByAddressAndScItem(QueryContractByCustomerDimensionRequest customerDimensionRequest) {
        List<MonthContractAndRollingCountResponse> contractAndRollingContResponses = contractRepository.queryQuantityListByAddressAndScItem(customerDimensionRequest);
        return Result.success(contractAndRollingContResponses);
    }

    @Override
    @FacadeInvoker
    public Result<PageResult<List<ContractSDO>>> queryDepartmentContractWithRedCount(PageQueryContractRequest contractRequest) {
        PageResult<List<ContractSDO>> doPageQuery = contractRepository.pageQueryDepartByRedCount(contractRequest);
        return Result.success(doPageQuery);
    }

}
